<!--
 * @页面名称:
 * @描述:
 * @作者: 辛慰
 * @Date: 2019-06-04 10:55:43
 -->
<template>
  <div class="con-item">
    <div class="con-box" v-for="(item,index) in videoInfo" :key="index">
      <p class="camera-title">{{ item.name }}</p>
      <div class="camera-box">
        <div class="left">
          <p class="l-title">实时视频</p>
          <div class="video">
            <video-player  class="video-player vjs-custom-skin"
              ref="videoPlayer"
              :playsinline="true"
              :options="playerOptions"
            ></video-player>
          </div>
        </div>
        <div class="right">
          <p class="r-title">短视频</p>
          <div class="short-video">
            <div class="short-video-item" v-for="(subItem,subIndex) in item.shortVideos" :key="subIndex" @click="reviewImage(subItem.videourl)">
              <img :src="subItem.imageurl">
            </div>
          </div>
        </div>
      </div>
    </div>
    <div v-if="dialogImageVisible" class="modalBox">
      <div class="modal">
        <video class="modalImg" :src="videos" autoplay="autoplay" controls></video>
        <img src="../assets/image/quxiao.png" class="modalIcon" @click="checkDisappear">
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      playerOptions: {
        playbackRates: [0.7, 1.0, 1.5, 2.0], // 播放速度
        autoplay: false, // 如果true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [{
          type: 'video/mp4',
          // src: "../assets/test02.mp4" //url地址
          src: 'https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm' // url地址
        }],
        poster: '../assets/005.jpg', // 你的封面地址
        // width: document.documentElement.clientWidth,
        notSupportedMessage: '此视频暂无法播放，请稍后再试', // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true // 全屏按钮
        }
      },
      videoInfo: [],
      dialogImageVisible: false,
      videos: ''
    }
  },
  props: ['msg'],
  created () {
    this.getRecordData()
  },
  methods: {
    reviewImage (src) {
      console.log(src)
      this.videos = 'http://192.168.1.114:5000' + 'src'
      this.dialogImageVisible = true
    },
    checkDisappear () {
      this.dialogImageVisible = false
    },
    getRecordData () {
      console.log(this.msg)
      this.msg.forEach(item => {
        this.$http.get('/api/Screen/GetDeviceRecord', {
          params: {
            deviceId: item.id,
            pageIndex: 1,
            pageSize: 10
          }
        }).then((res) => {
          item['shortVideos'] = res.data.data
          this.videoInfo.push(item)
          console.log(this.videoInfo)
        })
      })
    }
  }
}
</script>

<style scoped>
.con-box {
  margin-bottom: .2rem;
}
.camera-title {
  height: .4rem;
  line-height: .4rem;
  font-size: .18rem;
  color: #000;
  font-weight: 700;
  margin-bottom: .2rem;
}
.camera-box {
  display: flex;
}
.left,.right {
  flex: 1;
}
.left {
  margin-right: .2rem;
}
.l-title,.r-title {
  height: .3rem;
  line-height: .3rem;
  font: bold .14rem #333;
  margin-bottom: .1rem;
}
.video {
  width: 100%;
  height: 4rem;
}
.short-video {
  width: 100%;
  height: 4rem;
  border: 1px solid #ccc;
  padding: .1rem;
  box-sizing: border-box;
  overflow-y: scroll;
}
.short-video-item {
  width: 1.2rem;
  height: .8rem;
  margin-right: .1rem;
  float: left;
  border: 1px solid #ccc;
  box-sizing: border-box;
  position: relative;
  cursor: pointer;
}
.short-video-item img {
  width: 100%;
  height: 100%;
  display: block;
}
.playIcon {
  width: .24rem;
  height: .24rem;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
.playIcon img {
  width: 100%;
  height: 100%;
  display: block;
}
.modal{
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
  z-index: 1000;
}
.modalImg{
  width: 6.8rem;
  height: 4.2rem;
  z-index: 1001;
  position: relative;
  top: 1.34rem;
}
.modalIcon{
  width: .5rem;
  height: .5rem;
  position: relative;
  top: 2.2rem;
  left: -3.63rem;
  cursor: pointer;
}
/*滚动条整体样式*/
.short-video::-webkit-scrollbar {
  width: 10px;
  height: 1px;
}
/*滚动条滑块*/
.short-video::-webkit-scrollbar-thumb {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
  background-image: -webkit-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.2) 75%,
    transparent 75%,
    transparent
  );
}
/*滚动条轨道*/
.short-video::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 1px rgba(0,0,0,0);
  border-radius: 10px;
  background: #ccc;
}
.short-video::-webkit-scrollbar-thumb:hover { /*滚动条的hover样式*/
  height: 50px;
  background-color: #9f9f9f;
  -webkit-border-radius: 4px;
}
</style>
